/*
 * @Author: 晟松
 * @Date: 2021-12-14 21:06:33
 * @LastEditors: 晟松
 * @LastEditTime: 2022-02-06 21:59:32
 * @FilePath: \mini-vue3d:\Code\node\koa2\volunteer-service\src\main\controller\MessageController.js
 * @Description:
 */
import Router from "koa-router";
import koaBodyparser from "koa-bodyparser";
import MessageService from "@main/service/MessageService";

let messageRouter = new Router({
    prefix: "/api/message",
});
/**
 * @description: 获得跟自己相关的消息
 * @param {*}
 * @return {*}
 */
messageRouter.post("/getMineMessage", koaBodyparser(), async (ctx) => {
    let user = ctx.state.user;
    let params = ctx.request.body;
    ctx.body = ctx.renderJson(
        await MessageService.getMineMessage(user, params)
    );
});

/**
 * @description: 辅导员或者居委会获取自己所发送的消息
 * @param {*}
 * @return {*}
 */
 messageRouter.post("/getMineMessageList", koaBodyparser(), async (ctx) => {
    let user = ctx.state.user;
    let params = ctx.request.body;
    ctx.body = ctx.renderJson(
        await MessageService.getMineMessageList(user, params)
    );
});

/**
 * @description: 获得一个message的信息
 * @param {*}
 * @return {*}
 */
messageRouter.post("/getOneMessage", koaBodyparser(), async (ctx) => {
    // let user = ctx.state.user;
    let params = ctx.request.body;
    ctx.body = ctx.renderJson(
        await MessageService.getOneMessage(params)
    );
});

messageRouter.post("/addOneMessage", koaBodyparser(), async (ctx) => {
    let params = ctx.request.body;
    ctx.body = ctx.renderJson(await MessageService.addOneMessage(params));
});
messageRouter.post("/addGlobalMessage", koaBodyparser(), async (ctx) => {
    let params = ctx.request.body;
    ctx.body = ctx.renderJson(await MessageService.addGlobalMessage(params));
});

export default messageRouter;
